package com.coreJava.设计模式.责任链模式的过滤器;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者: LCG
 * 日期: 2019/9/5 16:12
 * 描述:
 */
public class MyFilterChainImpl implements MyFilterChain {

        List<MyFilter>  list=new ArrayList<>();


        public void registerFilter(MyFilter myFilter){
           list.add(myFilter);
        }

        public void registerFilter(MyFilter myFilter,int order){
            list.add(order,myFilter);
        }

        private int index=0;

        @Override
        public void chain() {
            if(index <list.size() ){
                MyFilter myFilter = list.get(index);
                index++;
                myFilter.doFilter(this);
            }
        }
}
